home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MIDICraft's MIDINET CD-ROM
/
MIDICraft's MIDINET CD-ROM.iso
/
DOSUTILS
/
KORG
/
TIMER.BAK
< prev
next >
Wrap
Text File
|
1996-11-02
|
1KB
|
77 lines
#include "timer.hpp"
#include <assert.h>
#include <dos.h>
#pragma option -N-
Timer* timer = 0;
#ifdef __cplusplus
#define __CPPARGS ...
#else
#define __CPPARGS
#endif
void interrupt ( *oldtimer)(__CPPARGS);
#define INT_TIMER 8
#pragma warn -eas
void interrupt timeinterrupt(__CPPARGS)
{
if (timer)
timer->ontime();
oldtimer();
}
#pragma warn .eas
Timer::Timer()
{
timer = 0;
curtime_ = 0;
setspeed(SPEED_DEFAULT);
oldtimer = getvect(INT_TIMER);
setvect(INT_TIMER, timeinterrupt);
timer = this;
}
Timer::~Timer()
{
timer = 0;
setspeed(SPEED_DEFAULT);
setvect(INT_TIMER, oldtimer);
}
void Timer::ontime()
{
curtime_++;
}
unsigned Timer::setspeed(unsigned speed)
{
if (speed < SPEED_MILLISEC)
speed = SPEED_MILLISEC;
disable();
asm mov al,36h
asm out 43h,al
asm mov ax, speed
asm out 40h, al
asm mov al,ah
asm out 40h, al
enable();
return speed;
}
// times interrupts in millisec
unsigned Timer::setspeed(unsigned millisec, unsigned times)
{
long speed = 0x123456L * millisec / (1000 * times);
if (speed >= 0x10000)
speed = 0xffff;
return setspeed(speed);
}